package com.example.haojiutao.service.impl;



import com.example.haojiutao.common.Result;
import com.example.haojiutao.mapper.CommentMapper;
import com.example.haojiutao.model.domain.Comment;
import com.example.haojiutao.model.vo.response.CommentGoodsDetailVO;
import com.example.haojiutao.model.vo.response.CommentOrderDetailVO;
import com.example.haojiutao.model.vo.response.OrderGoodsDetailVO;
import com.example.haojiutao.service.CommentService;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;
import java.util.List;

/**
 * @Description:
 * @Author: zhou_yuan
 * @CreateTime： 2024/1/20 15:47
 */
@Slf4j
@Service
public class CommentServiceImpl implements CommentService {
    @Autowired
    private CommentMapper commentMapper;

//    /*
//     *  添加评论
//     **/
    @Override
    public Result insert(Comment comment){
        String level=comment.getLevel();
        String content=comment.getContent();
        System.out.println("---------------"+level+"-----"+content);
        if(!StringUtils.hasLength(level) || !StringUtils.hasLength(content)
        ){
            log.warn("用户评论信息为空，level ={},content ={}," ,level,content);
            return Result.faile(100001,"评分和评论内容不能为空哦");
        }
        int rows=commentMapper.insertComment(comment);
        if(rows==1){
            log.info("评论信息：{}",comment);
            return Result.success("评论成功");
        }
            return Result.faile("没有提交星级评价");
    }


    /*
     *  删除评论

     **/
    @Override
    public Result deleteById(Integer id) {

        Comment comment=new Comment();
//        comment.setUserId(2);
        int rows= commentMapper.deleteById(id);
        if(rows==1){
            return Result.success("评论删除成功");
        }else {
            return Result.faile("评论删除失败");
        }

    }

    /*
     * @Description:列表查询，查询所有评论
     * @Author: zhou_yuan
     * @CreateTime： 2024/1/20 15:50
     * @param: comment
     * @return: java.util.List<com.example.secondhand.domain.Comment>
     **/
    @Override
    public List<Comment> listByComment(Comment comment) {

        PageHelper.startPage(comment.getPageNum(),comment.getPageSize());//在apifox中自行输入pageNUm,pageSize的参数
        List<Comment> comments=commentMapper.selectListByUser(comment);
        return comments;

    }
    /*
     * @Description: 根据用户ID查询评论
     * @Author: zhou_yuan
     * @CreateTime： 2024/1/20 15:50
     * @param: userId
     * @return: java.util.List<com.example.secondhand.domain.Comment>
     **/
    @Override
    public List<Comment> selectByUserIdComments(String userName) {
        return commentMapper.selectByUserIdComments(userName);
    }



    /*
     * @Description: 根据id查询
     * @Author: zhou_yuan
     * @CreateTime： 2024/1/20 15:55
     * @param: commentId
     * @return: com.example.haojiutao.common.Result
     */
    @Override
    public CommentGoodsDetailVO selectByCommentId(Integer commentId) {
        CommentGoodsDetailVO comment = commentMapper.selectByCommentId(commentId);
        log.info("comment={}" + comment);
        return comment;
    }

    /*
     * @Description: 待评价
     * @Author: zhou_yuan
     * @CreateTime： 2024/1/20 16:08
     * @param: comment
     * @return: java.util.List<com.example.haojiutao.model.vo.response.CommentOrderGoodsDetailVO>
     */
    @Override
    public List<OrderGoodsDetailVO> selectBeforeComment(OrderGoodsDetailVO order) {
        PageHelper.startPage(order.getPageNum(), order.getPageSize());
        List<OrderGoodsDetailVO> comment1 = commentMapper.selectBeforeComment(order);
        return comment1;
    }
    /*
     * @Description: 可追评
     * @Author: zhou_yuan
     * @CreateTime： 2024/1/20 16:10
     * @param: comment
     * @return: java.util.List<com.example.haojiutao.model.vo.response.CommentOrderGoodsDetailVO>
     */
    @Override
    public List<CommentGoodsDetailVO> selectReComment(CommentGoodsDetailVO comment) {
        PageHelper.startPage(comment.getPageNum(), comment.getPageSize());
        List<CommentGoodsDetailVO> comment1 = commentMapper.selectReComment(comment);
        return comment1;
    }


}
